Page({
  data: {
    houses: [],
    inpValue: ''
  },
  handleInput(e) {
    const { value } = e.detail;
    console.log(value);
    // 如果为空
    if (!value.trim()) {
      setTimeout(() => {
        this.setData({
          houses: []
        })
      }, 100)
      return;
    }
    else{
      setTimeout(() => {
        this.setData({
          inpValue: e.detail.value
        })
      }, 100)
    }
    this.qsearch(value);
  },
  qsearch(query) {
    let that = this
    const db = wx.cloud.database()
    db.collection('house_information').where({
      title: db.RegExp({
        regexp: query,
        options: 'i',
      })
    }).get({
      success: function (res) {
        that.setData({
          houses: res.data
        })
      }
    })
  },
  handleSearch() {
    wx.navigateTo({
      url: '/pages/house_list/house_list?title=' + this.data.inpValue,
    });
  }
})